package com.tianyi.wz.walkinggame.biz;

import android.app.Activity;
import android.util.Log;

import com.tianyi.wz.walkinggame.Constant;

import org.apache.commons.lang3.StringUtils;

import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class RewardBiz {

    Activity mActivity;

    public RewardBiz(Activity activity){
        mActivity = activity;
    }

    private static OkHttpClient client;

    static {
        client = new OkHttpClient.Builder().build();
    }

    public void reward(String userId,String appId,String codeId){
        if(StringUtils.isEmpty(userId) || StringUtils.isEmpty(appId) || StringUtils.isEmpty(codeId)){
            Log.e(LogBiz.class.getName(), Constant.MESSAGE.MISSING_PARAMETER);
            return;
        }
        new Thread(() ->{
            try {
                FormBody body = new FormBody.Builder()
                        .add("token", userId)
                        .add("appid", appId)
                        .add("ad", codeId).build();
                Request req = new Request.Builder().url(Constant.INTERFACE.TBS_REWARD).post(body).build();
                Response rep = client.newCall(req).execute();
                Log.d(LogBiz.class.getName(), rep.body().string());
            } catch (Exception e) {
                Log.e(LogBiz.class.getName(), e.getMessage(), e);
            }
        }).start();
    }

}
